package java44th.group.service.admin.footprint;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import java44th.group.bean.common.BasePageInfo;
import java44th.group.bean.common.CommonData;
import java44th.group.bean.po.MarketFootprint;
import java44th.group.bean.po.MarketFootprintExample;
import java44th.group.mapper.MarketFootprintMapper;
import java44th.group.service.admin.footprint.FootprintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ProjectName project-second
 * @Descriptiom TODO
 * @Aurhor: 蔡文强
 * @Since: 2022/10/12 20:43
 */
@Service
public class FootprintServiceImpl implements FootprintService {

    @Autowired
    MarketFootprintMapper marketFootprintMapper;

    @Override
    public CommonData<MarketFootprint> list(BasePageInfo basePageInfo, Integer userId, Integer goodsId) {

        PageHelper.startPage(basePageInfo.getPage(), basePageInfo.getLimit());

        MarketFootprintExample example = new MarketFootprintExample();
        example.setOrderByClause(basePageInfo.getSort() + " " + basePageInfo.getOrder());
        MarketFootprintExample.Criteria criteria = example.createCriteria();
        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }
        if (goodsId != null) {
            criteria.andGoodsIdEqualTo(goodsId);
        }
        List<MarketFootprint> marketFootprints = marketFootprintMapper.selectByExample(example);

        PageInfo<MarketFootprint> marketFootprintPageInfo = new PageInfo<>(marketFootprints);

        return CommonData.data(marketFootprintPageInfo);
    }
}
